package com.qianda.qdminiapp.controller.activity;


import com.qianda.qdminiapp.controller.Result;
import com.qianda.qdminiapp.domain.dto.DrawRedpacketDto;
import com.qianda.qdminiapp.domain.model.activity.QqdRedpacketActivity;
import com.qianda.qdminiapp.security.SecurityUser;
import com.qianda.qdminiapp.service.QqdRedpacketActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 红包活动 前端控制器
 * </p>
 *
 * @author cw
 * @since 2020-07-15
 */
@RestController
@RequestMapping("/qqd-redpacket-activity")
public class QqdRedpacketActivityController {

    @Autowired
    private QqdRedpacketActivityService qqdRedpacketActivityService;

    /**
     * 获取红包详情
     * @param orderId
     * @param user
     * @return
     */
    @GetMapping("/getRedpacketDetail/{orderId}")
    public Result getRedpacketDetail(@PathVariable Long orderId,Long userId, @AuthenticationPrincipal SecurityUser user){

        return Result.success(qqdRedpacketActivityService.getRedpacketActivity(user.getId(),orderId));
    }

    /**
     * 领取红包
     * @param drawRedpacketDto
     * @param user
     * @return
     */
    @PostMapping("/drawRedpacket")
    public Result getRedpacketDetail(@RequestBody DrawRedpacketDto drawRedpacketDto , @AuthenticationPrincipal SecurityUser user){
        drawRedpacketDto.setUserId(user.getId());
        return Result.success( qqdRedpacketActivityService.drawRedpacket(drawRedpacketDto,drawRedpacketDto.getUserId()));
    }

}

